package com.qiwenshare.file.handler;

/**
 * @author CZF
 * @create 2024-01-22 1:06
 */
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qiwenshare.file.service.ClickRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

@Component
public class WebInterceptor implements HandlerInterceptor {

    @Autowired
    ClickRecordService clickRecordService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        // 在请求处理之前进行拦截
//        System.out.println("Pre-handle method is called. Request URI: " + request.getRequestURI());
        return true; // 返回true表示继续执行请求，返回false表示中断请求
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
        // 请求处理之后进行拦截，但在视图被渲染之前
//        System.out.println("Post-handle method is called. Request URI: " + request.getRequestURI());
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        // 请求处理完成之后进行拦截，包括视图渲染完成
//        System.out.println("After-completion method is called. Request URI: " + request.getRequestURI());
    }
}
